package com.timous.tree;

import sun.reflect.generics.tree.Tree;

import java.util.ArrayList;
import java.util.List;

/**
 * https://leetcode-cn.com/problems/binary-tree-preorder-traversal/
 */
public class _144_二叉树的前序遍历 {

    ArrayList<Integer> list = new ArrayList<>();
     public List<Integer> preorderTraversal(TreeNode root) {

         TreeNode node = root;
         if(node == null) return null;
         while (node != null){
             TreeNode left = node.left;
             TreeNode right = node.right;
             list.add(node.val);
             if(left != null){
                 preorderTraversal(left);
             }
             if(right != null){
                 preorderTraversal(right);
             }


         }
         return list;
     }


}
